package com.dodayum.controller;

import com.dodayum.dao.UserMapper;
import com.dodayum.pojo.User;
import com.dodayum.utils.ResultUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {

    @Resource
    UserMapper userMapper;

    @RequestMapping("/goLogin")
    public String goLogin() {
        return "login";
    }

    @RequestMapping("login")
    public String login(HttpSession session, String userName, String password) {
        List<User> login = userMapper.login(userName, password);
        int size = login.size();
        if (size == 1) {
            session.setAttribute("loginInfo", userName);
        } else if (size == 0) {
            return new ResultUtils(false, "账户名或密码错误", 500,"JSON").buildReturn();
        } else {
            return new ResultUtils(false, "有脏数据", 500,"JSON").buildReturn();
        }
        return "main";
    }
}
